//时间复杂度O(n^2)
#include <iostream>
using namespace std;

const int N = 1010;
int n;
int a[N];
int f[N];
int g[N];
int res = 0;

int main()
{
    freopen("cin.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    //预处理
    for (int i = 1; i <= n; ++i) //找到以i结尾的最长上升子序列的长度
    {
        f[i] = 1; //我至少有我自己
        for (int j = 1; j < i; ++j)
            if (a[i] > a[j])
                f[i] = max(f[i], f[j] + 1);
    }
    for (int i = n; i > 0; --i) //相当于把最长上升子序列轴对称，找到的是以i开头的最长下降子序列
    {
        g[i] = 1;
        for (int j = n; j > i; --j)
            if (a[i] > a[j])
                g[i] = max(g[i], g[j] + 1);
    }
    for (int i = 1; i <= n; ++i) //找到以i为中转的路线
        res = max(res, f[i] + g[i] - 1);
    cout << res;
    return 0;
}